<template>
  <div class="user-avatar-dropdown">
    <Dropdown @on-click="handleClick">
      <Badge :dot="!!messageUnreadCount">
        <Avatar :src="userAvatar"/><span style="margin: 0 5px 0 5px">{{username}}</span>
      </Badge>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
<!--        <DropdownItem name="message">
          消息中心<Badge style="margin-left: 10px" :count="messageUnreadCount"></Badge>
        </DropdownItem>-->
        <DropdownItem  name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
export default {
  name: 'user',
  props: {
    userAvatar: {
      type: String,
      default: 'http://47.108.140.232:9000/supervisor/Avatar/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20201109155027.png'
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    dologout () {
      let that = this
        this.http.auth("/loginout").then(res=>{
          if(res.data){
           this.$Modal.success({
             title:"提示",
             content:"成功退出",
             onOk(){
               that.$store.commit("setToken","")
               window.location.reload();
             }
           })
          }
        })
    },
    message () {
      this.$router.push({
        name: 'message_page'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout': this.dologout()
          break
        case 'message': this.message()
          break
      }
    }
  },
  computed:{
    username(){
      return this.$store.state.user.user.name
    }
  }
}
</script>
